3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
23 * This class is used to get a list of active users. The ones with specials
24 * rights (sysop, bureaucrat, developer) will have them displayed
25 * next to their names.
29 class ActiveUsersPager
extends UsersPager
{
44 private $blockStatusByUid;
47 * @param IContextSource|null $context
48 * @param FormOptions $opts
50 public function __construct( IContextSource
$context = null, FormOptions
$opts ) {
51 parent
::__construct( $context );
53 $this->RCMaxAge
= $this->getConfig()->get( 'ActiveUserDays' );
54 $this->requestedUser
= '';
56 $un = $opts->getValue( 'username' );
58 $username = Title
::makeTitleSafe( NS_USER
, $un );
59 if ( !is_null( $username ) ) {
60 $this->requestedUser
= $username->getText();
64 $this->groups
= $opts->getValue( 'groups' );
65 $this->excludegroups
= $opts->getValue( 'excludegroups' );
66 // Backwards-compatibility with old URLs
67 if ( $opts->getValue( 'hidebots' ) ) {
68 $this->excludegroups
[] = 'bot';
70 if ( $opts->getValue( 'hidesysops' ) ) {
71 $this->excludegroups
[] = 'sysop';
75 function getIndexField() {
79 function getQueryInfo() {
80 $dbr = $this->getDatabase();
82 $rcQuery = ActorMigration
::newMigration()->getJoin( 'rc_user' );
84 $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
85 $timestamp = $dbr->timestamp( wfTimestamp( TS_UNIX
) - $activeUserSeconds );
86 $tables = [ 'querycachetwo', 'user', 'rc' => [ 'recentchanges' ] +
$rcQuery['tables'] ];
88 'user' => [ 'JOIN', 'user_name = qcc_title' ],
89 'rc' => [ 'JOIN', $rcQuery['fields']['rc_user_text'] . ' = qcc_title' ],
90 ] +
$rcQuery['joins'];
92 'qcc_type' => 'activeusers',
93 'qcc_namespace' => NS_USER
,
94 'rc_type != ' . $dbr->addQuotes( RC_EXTERNAL
), // Don't count wikidata.
95 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE
), // Don't count categorization changes.
96 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' ),
97 'rc_timestamp >= ' . $dbr->addQuotes( $timestamp ),
99 if ( $this->requestedUser
!= '' ) {
100 $conds[] = 'qcc_title >= ' . $dbr->addQuotes( $this->requestedUser
);
102 if ( $this->groups
!== [] ) {
103 $tables[] = 'user_groups';
104 $jconds['user_groups'] = [ 'JOIN', [ 'ug_user = user_id' ] ];
105 $conds['ug_group'] = $this->groups
;
106 $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() );
108 if ( $this->excludegroups
!== [] ) {
109 foreach ( $this->excludegroups
as $group ) {
110 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
111 'user_groups', '1', [
113 'ug_group' => $group,
114 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
119 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
120 $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
121 'ipblocks', '1', [ 'ipb_user=user_id', 'ipb_deleted' => 1 ]
129 'user_name' => 'qcc_title',
130 'user_id' => 'MAX(user_id)',
131 'recentedits' => 'COUNT(*)'
133 'options' => [ 'GROUP BY' => [ 'qcc_title' ] ],
135 'join_conds' => $jconds,
139 protected function doBatchLookups() {
140 parent
::doBatchLookups();
143 foreach ( $this->mResult
as $row ) {
144 $uids[] = $row->user_id
;
146 // Fetch the block status of the user for showing "(blocked)" text and for
147 // striking out names of suppressed users when privileged user views the list.
148 // Although the first query already hits the block table for un-privileged, this
149 // is done in two queries to avoid huge quicksorts and to make COUNT(*) correct.
150 $dbr = $this->getDatabase();
151 $res = $dbr->select( 'ipblocks',
152 [ 'ipb_user', 'MAX(ipb_deleted) AS deleted, MAX(ipb_sitewide) AS sitewide' ],
153 [ 'ipb_user' => $uids ],
155 [ 'GROUP BY' => [ 'ipb_user' ] ]
157 $this->blockStatusByUid
= [];
158 foreach ( $res as $row ) {
159 $this->blockStatusByUid
[$row->ipb_user
] = [
160 'deleted' => $row->deleted
,
161 'sitewide' => $row->sitewide
,
164 $this->mResult
->seek( 0 );
167 function formatRow( $row ) {
168 $userName = $row->user_name
;
170 $ulinks = Linker
::userLink( $row->user_id
, $userName );
171 $ulinks .= Linker
::userToolLinks( $row->user_id
, $userName );
173 $lang = $this->getLanguage();
176 $user = User
::newFromId( $row->user_id
);
178 $ugms = self
::getGroupMemberships( intval( $row->user_id
), $this->userGroupCache
);
179 foreach ( $ugms as $ugm ) {
180 $list[] = $this->buildGroupLink( $ugm, $userName );
183 $groups = $lang->commaList( $list );
185 $item = $lang->specialList( $ulinks, $groups );
187 // If there is a block, 'deleted' and 'sitewide' are both set on
188 // $this->blockStatusByUid[$row->user_id].
190 $isBlocked = isset( $this->blockStatusByUid
[$row->user_id
] );
192 if ( $this->blockStatusByUid
[$row->user_id
]['deleted'] == 1 ) {
193 $item = "<span class=\"deleted\">$item</span>";
195 if ( $this->blockStatusByUid
[$row->user_id
]['sitewide'] == 1 ) {
196 $blocked = ' ' . $this->msg( 'listusers-blocked', $userName )->escaped();
199 $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits
)
200 ->params( $userName )->numParams( $this->RCMaxAge
)->escaped();
202 return Html
::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );